home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
ZSI
/
schema.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
10KB
|
318 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from ZSI import _copyright, _seqtypes, _find_type, _get_element_nsuri_name, EvaluateException
from ZSI.wstools.Namespaces import SCHEMA, SOAP
from ZSI.wstools.Utility import SplitQName
def _get_type_definition(namespaceURI, name, **kw):
return SchemaInstanceType.getTypeDefinition(namespaceURI, name, **kw)
def _get_global_element_declaration(namespaceURI, name, **kw):
return SchemaInstanceType.getElementDeclaration(namespaceURI, name, **kw)
def _get_substitute_element(head, elt, ps):
if not isinstance(head, ElementDeclaration):
return None
return ElementDeclaration.getSubstitutionElement(head, elt, ps)
def _has_type_definition(namespaceURI, name):
return SchemaInstanceType.getTypeDefinition(namespaceURI, name) is not None
def _is_substitute_element(head, sub):
if not isinstance(head, ElementDeclaration) or not isinstance(sub, ElementDeclaration):
return False
try:
group = sub.substitutionGroup
except (AttributeError, TypeError):
return False
ged = GED(*group)
if head.nspname == ged.nspname:
pass
print head.pname == ged.pname
if not head is ged:
if head.nspname == ged.nspname:
pass
if not (head.pname == ged.pname):
return False
return True
GED = _get_global_element_declaration
GTD = _get_type_definition
def WrapImmutable(pyobj, what):
return _GetPyobjWrapper.WrapImmutable(pyobj, what)
def RegisterBuiltin(arg):
_GetPyobjWrapper.RegisterBuiltin(arg)
_GetPyobjWrapper.RegisterAnyElement()
def RegisterAnyElement():
return _GetPyobjWrapper.RegisterAnyElement()
class SchemaInstanceType(type):
types = { }
elements = { }
element_typecode_cache = { }
def __new__(cls, classname, bases, classdict):
if classname in ('ElementDeclaration', 'TypeDefinition', 'LocalElementDeclaration'):
return type.__new__(cls, classname, bases, classdict)
if ElementDeclaration in bases:
if classdict.has_key('schema') is False or classdict.has_key('literal') is False:
raise AttributeError, 'ElementDeclaration must define schema and literal attributes'
key = (classdict['schema'], classdict['literal'])
if SchemaInstanceType.elements.has_key(key):
return SchemaInstanceType.elements[key]
ged = SchemaInstanceType.elements[key] = type.__new__(cls, classname, bases, classdict)
return ged
if TypeDefinition in bases:
if classdict.has_key('type') is None:
raise AttributeError, 'TypeDefinition must define type attribute'
key = classdict['type']
if SchemaInstanceType.types.has_key(key) is False:
SchemaInstanceType.types[key] = type.__new__(cls, classname, bases, classdict)
return SchemaInstanceType.types[key]
if LocalElementDeclaration in bases:
return type.__new__(cls, classname, bases, classdict)
raise TypeError, 'SchemaInstanceType must be an ElementDeclaration or TypeDefinition '
def getTypeDefinition(cls, namespaceURI, name, lazy = False):
klass = cls.types.get((namespaceURI, name), None)
if lazy and klass is not None:
return _Mirage(klass)
return klass
getTypeDefinition = classmethod(getTypeDefinition)
def getElementDeclaration(cls, namespaceURI, name, isref = False, lazy = False):
key = (namespaceURI, name)
if isref:
klass = cls.elements.get(key, None)
if klass is not None and lazy is True:
return _Mirage(klass)
return klass
typecode = cls.element_typecode_cache.get(key, None)
if typecode is None:
tcls = cls.elements.get(key, None)
if tcls is not None:
typecode = cls.element_typecode_cache[key] = tcls()
typecode.typed = False
return typecode
getElementDeclaration = classmethod(getElementDeclaration)
class ElementDeclaration:
__metaclass__ = SchemaInstanceType
def checkSubstitute(self, typecode):
if not isinstance(typecode, ElementDeclaration):
return False
try:
(nsuri, ncname) = typecode.substitutionGroup
except (AttributeError, TypeError):
return False
if (nsuri, ncname) != (self.schema, self.literal):
if not nsuri and not (self.schema) and ncname == self.literal:
return True
return False
sub = GED(self.schema, self.literal)
if sub is None or sub is not typecode:
return False
return True
def getSubstitutionElement(self, elt, ps):
(nsuri, ncname) = _get_element_nsuri_name(elt)
typecode = GED(nsuri, ncname)
if typecode is None:
return None
try:
(nsuri, ncname) = typecode.substitutionGroup
except (AttributeError, TypeError):
return None
if ncname == self.pname:
if (nsuri == self.nspname or not nsuri) and not (self.nspname):
return typecode
class LocalElementDeclaration:
__metaclass__ = SchemaInstanceType
class TypeDefinition:
__metaclass__ = SchemaInstanceType
def getSubstituteType(self, elt, ps):
pyclass = SchemaInstanceType.getTypeDefinition(*self.type)
if pyclass is None:
raise EvaluateException('No Type registed for xsi:type=(%s, %s)' % (self.type[0], self.type[1]), ps.Backtrace(elt))
typeName = _find_type(elt)
(prefix, typeName) = SplitQName(typeName)
uri = ps.GetElementNSdict(elt).get(prefix)
if uri is None:
uri = self.nspname
subclass = SchemaInstanceType.getTypeDefinition(uri, typeName)
if subclass is None:
raise EvaluateException('No registered xsi:type=(%s, %s), substitute for xsi:type=(%s, %s)' % (uri, typeName, self.type[0], self.type[1]), ps.Backtrace(elt))
if not issubclass(subclass, pyclass) and subclass(None) and not issubclass(subclass, pyclass):
raise TypeError('Substitute Type (%s, %s) is not derived from %s' % (self.type[0], self.type[1], pyclass), ps.Backtrace(elt))
return subclass((self.nspname, self.pname))
class _Mirage:
def __init__(self, klass):
self.klass = klass
self._Mirage__reveal = False
self._Mirage__cache = None
if issubclass(klass, ElementDeclaration):
self.__call__ = self._hide_element
def __str__(self):
msg = '<Mirage id=%s, Local Element %s>'
if issubclass(self.klass, ElementDeclaration):
msg = '<Mirage id=%s, GED %s>'
return msg % (id(self), self.klass)
def _hide_type(self, pname, aname, minOccurs = 0, maxOccurs = 1, nillable = False, **kw):
self.__call__ = self._reveal_type
self._Mirage__reveal = True
self._Mirage__kw = kw
self.minOccurs = minOccurs
self.maxOccurs = maxOccurs
self.nillable = nillable
self.nspname = None
self.pname = pname
self.aname = aname
if type(self.pname) in (tuple, list):
(self.nspname, self.pname) = pname
return self
def _hide_element(self, minOccurs = 0, maxOccurs = 1, nillable = False, **kw):
self.__call__ = self._reveal_element
self._Mirage__reveal = True
self._Mirage__kw = kw
self.nspname = self.klass.schema
self.pname = self.klass.literal
self.minOccurs = minOccurs
self.maxOccurs = maxOccurs
self.nillable = nillable
return self
def _reveal_type(self):
if self._Mirage__cache is None:
self._Mirage__cache = self.klass(pname = self.pname, aname = self.aname, minOccurs = self.minOccurs, maxOccurs = self.maxOccurs, nillable = self.nillable, **self._Mirage__kw)
return self._Mirage__cache
def _reveal_element(self):
if self._Mirage__cache is None:
self._Mirage__cache = self.klass(minOccurs = self.minOccurs, maxOccurs = self.maxOccurs, nillable = self.nillable, **self._Mirage__kw)
return self._Mirage__cache
__call__ = _hide_type
class _GetPyobjWrapper:
types_dict = dict()
def RegisterBuiltin(cls, arg):
if arg in cls.types_dict:
raise RuntimeError, '%s already registered' % arg
class _Wrapper('_Wrapper', (arg,)):
'Wrapper for builtin %s\n%s' % (arg, cls.__doc__)
_Wrapper.__name__ = '_%sWrapper' % arg.__name__
cls.types_dict[arg] = _Wrapper
RegisterBuiltin = classmethod(RegisterBuiltin)
def RegisterAnyElement(cls):
for k, v in cls.types_dict.items():
what = Any.serialmap.get(k)
if what is None:
continue
if v in what.__class__.seriallist:
continue
what.__class__.seriallist.append(v)
RegisterType(what.__class__, clobber = 1, **what.__dict__)
RegisterAnyElement = classmethod(RegisterAnyElement)
def WrapImmutable(cls, pyobj, what):
d = cls.types_dict
if type(pyobj) is bool:
pyclass = d[int]
elif d.has_key(type(pyobj)) is True:
pyclass = d[type(pyobj)]
else:
raise TypeError, 'Expecting a built-in type in %s (got %s).' % (d.keys(), type(pyobj))
newobj = pyclass(pyobj)
newobj.typecode = what
return newobj
WrapImmutable = classmethod(WrapImmutable)
from TC import Any, RegisterType
if __name__ == '__main__':
print _copyright